home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1997 May
/
EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso
/
softwareupdate
/
system
/
amigados
/
filefunctions
/
functions.doc
< prev
next >
Wrap
Text File
|
1996-10-10
|
11KB
|
360 lines
3 FILE FUNCTIONS - FUNCTIONS
3.1 QUICK REFERENCE
Here is a complete list of all file functions described in this
chapter:
Function Description
------------------------------------------------------------
CreateDir() Creates a directory.
DeleteFile() Deletes a specified file or directory.
Relabel() Renames a specified volume.
Rename() Renames a specified file or directory.
SetComment() Adds a comment to a file or direcotry.
SetProtection() Alters the protection bits on a file or dir.
------------------------------------------------------------
---------------------------------------------------------------
CreateDir()
ROM library: "dos.library/CreateDir", (All versions)
#include <clib/dos_protos.h>
Creates a directory and puts an exclusive lock on it.
Synopsis: lock = CreateDir( dir_name );
lock: (BPTR) If the directory could be created or there
already exist a direcoty with the specified name
a BPTR (BPCL pointer) is returned. If the directory
on the other hand could not be created NULL is
returned.
dir_name: (STRPTR) Pointer to a text string which contains
the name of the new directory (including any
necessary path).
If you have successfully created a directory you must unlock it
as soon as you do not need the lock any more!
Here is a simple example on how to use the CreateDir()
function:
/* A "BCPL" pointer to our directory lock: */
BPTR my_dir_lock;
- - -
/* Try to create a directory: */
my_dir_lock = CreateDir( "Ram:MyDirectory" );
/* Check if we have successfully created */
/* the directory or not: */
if( my_dir_lock == NULL )
{
/* Problems! */
printf( "Could not create the directory!\n" );
exit( 20 );
}
- - -
/* When we do not need the directory lock */
/* any more we unlock it: */
UnLock( my_dir_lock );
See also: Lock(), UnLock()
---------------------------------------------------------------
DeleteFile()
ROM library: "dos.library/DeleteFile", (All versions)
#include <clib/dos_protos.h>
Deletes a specified file or directory.
Synopsis: ok = DeleteFile( name );
ok: (LONG) If the file/directory could be deleted TRUE is
returned, else FALSE is returned (the file/directory
could not be deleted).
name: (STRPTR) Pointer to a text string which contains
the name (including any necessary path) of the file
or directory you want to delete.
Remember that you can only delete empty directories.
Here is a simple example on how to use the DeleteFile()
function:
/* A simple boolean variable: */
BOOL ok;
/* Delete a file: */
ok = DeleteFile( "RAM:Unimportand.dat" );
/* Could we delete the file? */
if( ok )
printf( "File deleted!\n" );
else
printf( "File could not be deleted!\n" );
See also: Open(), CreateDir()
---------------------------------------------------------------
Relabel()
ROM library: "dos.library/Relabel", (V36+)
#include <clib/dos_protos.h>
Renames a specified volume.
Synopsis: ok = Relabel( old_name, new_name );
ok: (LONG) If the volume could be renamed TRUE is
returned, else FALSE is returned (the volume could
not be renamed).
old_name: (STRPTR) Pointer to a text string which contains
the name of the volume you want to rename. Since
this is the current volume name you have to include
the colons ":" at the end of the volume name.
new_name: (STRPTR) Pointer to a text string which contains
the new name of the volume. There should NOT be any
colons (:) at the end of this name since it is for
the moment not a volume name (but it will hopefully
soon be).
Note that this function was first included in dos library V36!
You can only rename volumes with this function. To rename a
file or directory you have to use the "Rename()" function.
Here is a simple example on how to use the Relabel() function:
/* A simple boolean variable: */
BOOL ok;
/* Rename the device: (We will try to rename the volume */
/* "Programs:" to "SourceCode".) */
ok = Relabel( "Programs:", "SourceCode" );
/* Could we rename the volume? */
if( ok )
printf( "The volume was successfully renamed!\n" );
else
printf( "The volume could not be renamed!\n" );
See also: Rename()
---------------------------------------------------------------
Rename()
ROM library: "dos.library/Rename", (All versions)
#include <clib/dos_protos.h>
Renames a specified file or directory. It is possible to rename
a file or directory so it is moved to another location on the
same volume.
Synopsis: ok = Rename( old_name, new_name );
ok: (LONG) If the file/directory could be renamed TRUE
is returned, else FALSE is returned (the file/
directory could not be renamed).
old_name: (STRPTR) Pointer to a text string which contains
the name (including any necessary path) of the file
or directory you want to rename.
new_name: (STRPTR) Pointer to a text string which contains
the new name (including any necessary path) of the
file or directory. The path may be different as
long as it is still on the same volume.
Note, you can not rename a file or directory to another volume!
You can not rename a volume with this function. You must then
instead use the new "Relabel()" function.
Here is a simple example on how to use the Rename() function:
/* A simple boolean variable: */
BOOL ok;
/* Rename a file: (We not only rename the actual file, but */
/* we also move the file inside a directory called "MyDir") */
ok = Rename( "RAM:HorribleName.doc", "RAM:MyDir/Good.doc" );
/* Could we rename the file? */
if( ok )
printf( "File renamed!\n" );
else
printf( "File could not be renamed!\n" );
See also: Relabel()
---------------------------------------------------------------
SetComment()
ROM library: "dos.library/SetComment", (All versions)
#include <clib/dos_protos.h>
Adds a comment to a file or direcotry.
Synopsis: ok = SetComment( file_name, comment );
ok: (LONG) If the comment could be attached to the file
or directory TRUE is returned, else FALSE is
returned (the comment could not be attached).
name: (STRPTR) Pointer to a text string which contains
the name (including any necessary path) of the file
or directory you want to add the comment to.
comment: (STRPTR) Pointer to a text string which contains
the comment you want to add. The comment can be up
to 80 characters long. (Any old comment will be
replaced.)
Here is a simple example on how to use the SetComment()
function:
/* A simple boolean variable: */
BOOL ok;
/* Add a comment to the file: */
ok = SetComment( "Ram:Hello.c", "My wonderful program!" );
/* Was the comment successfully added? */
if( ok )
printf( "The comment was successfully attached!\n" );
else
printf( "Error! Could not add the comment!\n" );
See also: -
---------------------------------------------------------------
SetProtection()
ROM library: "dos.library/SetProtection", (All versions)
#include <clib/dos_protos.h>
Alters the protection bits on a file or directory.
Synopsis: ok = SetComment( file_name, flags );
ok: (LONG) If the protection bits could be altered as
instructed the function returns TRUE, else FALSE is
returned (the protection bits could not be altered).
name: (STRPTR) Pointer to a text string which contains
the name (including any necessary path) of the file
or directory which protection bits you want to
alter.
flags: (LONG) The protection bits you want to alter. You
set and/oor removes the bits with help of the
following flags: (defined in header file
"dos/dos.h")
FIBF_DELETE:
If this flag is set the "d" bit is removed so
the file or directory can not be deleted. If
this flag is not set the "d" bit will be
added.
FIBF_EXECUTE:
If this flag is set the "e" bit is removed so
Shell (CLI) will refuse to start the file as a
program. If this flag is not set the "e" bit
will be added.
FIBF_WRITE:
If this flag is set the "w" bit is removed so
no one can alter the file. If this flag is not
set the "w" bit will be added.
FIBF_READ:
If this flag is set the "r" bit is removed so
no one can read the file. If this flag is not
set the "r" bit will be added.
FIBF_ARCHIVE:
If this flag is set the "a" bit will be added
which indicates that the file has been
archived. If this flag is not set the "a" bit
will be removed.
FIBF_PURE:
If this flag is set the "p" bit will be added
which tells the Shell command "Resident" that
this file is "pure" and can be made resident.
If this flag is not set the "p" bit will be
removed.
FIBF_SCRIPT:
If this flag is set the "s" bit will be added
which tells Shell that this file is a script.
If this flag is not set the "s" bit will be
removed.
Note that the first four flags will remove the
corresponding bits if the flags are set. The last
three flags will on the other hand set the
corresponding bits if the flags are set!
To set sveral flags simply add a "|" sign between
them. So to protect a file from being accidentally
deleted and to instruct the Shell that it is a
script you set this field to:
FIBF_DELETE | FIBF_SCRIPT
Note that the "e", "w" and "r" bits will also
be set and "a" and "p" removed!
Here is a simple example on how to use the SetProtection()
function:
/* A simple boolean variable: */
BOOL ok;
/* Protect the file from being accidentally deleted */
/* and tell Shell it is a script: */
ok = SetProtection( "S:PrepCompiler",
FIBF_DELETE | FIBF_SCRIPT );
/* Could we alter the protection bits as desired? */
if( ok )
printf( "The protection bits were successfully altered!\n" );
else
printf( "Error! Could not alter the protection bits!\n" );
See also: -
---------------------------------------------------------------